package com.ctrip.ec.biz.dao.goods;
import com.ctrip.ec.dal.DaoBase;
import com.ctrip.ec.biz.entity.goods.GoodsImageEntity;
import com.ctrip.ec.dal.DbAccess;
import com.ctrip.ec.dal.IdConvert;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.util.List;

@Service
public class GoodsImageDao extends DaoBase<GoodsImageEntity> {
    public GoodsImageDao() {
        super(GoodsImageEntity.class);
    }
    public GoodsImageDao(DbAccess db) {
        super(GoodsImageEntity.class,db);
    }

    public List<GoodsImageEntity> listByGoodsId(Long id) throws SQLException {
        String sql = "select * from " + this.getTableName() + " where goods_id=?";
        List<GoodsImageEntity> list = this.db.query(GoodsImageEntity.class,sql,id);
        return list;
    }

    public List<Long> getImageIds(List<Long> ids) throws SQLException {
        String sql = "select image_id from " + this.getTableName() + " where id in ("  + IdConvert.join(ids) + ")";
        return this.db.query(Long.class,sql);
    }
}
